package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView lstv=findViewById(R.id.lst);
        SimpleAdapter adapter=new SimpleAdapter(MainActivity.this,mylst(),R.layout.lstitem,new String[]{"image","title","info"},new int[]{R.id.image,R.id.title,R.id.info});
        lstv.setAdapter(adapter);
    }
    public ArrayList<Map<String,Object>> mylst()
    {
        ArrayList<Map<String,Object>> lst=new ArrayList<Map<String,Object>>();
        HashMap<String,Object> item1=new HashMap<String,Object>();
        HashMap<String,Object> item2=new HashMap<String,Object>();
        HashMap<String,Object> item3=new HashMap<String,Object>();
        item1.put("image",R.drawable.s1);
        item1.put("title","小明");
        item1.put("info","总经理");
        item2.put("image",R.drawable.s2);
        item2.put("title","小李");
        item2.put("info","经理");
        item3.put("image",R.drawable.s3);
        item3.put("title","小刚");
        item3.put("info","员工");
        lst.add(item1);
        lst.add(item2);
        lst.add(item3);
        return lst;
    }
}